<?php
//Feed
class Feed{
    public function __construct(){
        
    }   
    public function ListNewFeed(){
        
    }
    public function InsertFeed(){
        
    }
}
class CommonFeed extends Feed{
    public function __construct(){
        parent::__construct();
    }
    public function InsertFeed($cfe_user_id=0,$cfe_src_id,$cfe_type,$cfe_time){
        // cfe_type : 0 comment news    1 comment review      2 UserReview    3 UserRegister
        if(!$cfe_user_id){
            $myuser = new user();
            $cfe_user_id = $myuser->u_id;
        }
        $db = new db_execute('INSERT INTO common_feed(cfe_user_id,cfe_src_id,cfe_type,cfe_time) 
                              VALUES(
                                '.$cfe_user_id.',
                                '.$cfe_src_id.',
                                '.$cfe_type.',
                                '.$cfe_time.'
                              )');
        if($db->total != -1) {unset($db);return true;}
        else return false;
    }
    
    /**
     * @param time_start, time_end :Gioi han thoi gian lay Feed
     * limit : gioi han so feed lay ra
     * order_by_date : 0 - Sap xep giam dan theo date, 1- Sap xep tang dan theo date
     * */
    public function ListNewFeed($time_start = 0, $time_end = 0, $limit = 0, $order_by_date = 0, $addWhere = ''){
        $order = ' ORDER BY cfe_time DESC ';
        if($time_start && $time_end){
            $where = ' AND cfe_time >= '.$time_start.' AND cfe_time <= '.$time_end;
        }
        if($time_end && !$time_start){
            $where = ' AND cfe_time <= '.$time_end;
        }
        if($time_start && !$time_end){
            $where = ' AND cfe_time >= '.$time_start;
        }
        if(!$time_start && !$time_end) $where = '';
        if($addWhere){
            $where .= ' AND '.$addWhere;
        }
        /*----------------*/
        if($limit){
            $limit_str = ' LIMIT '.$limit;
        }
        if($order_by_date){
            $order = ' ORDER BY cfe_time ASC ';
        }
        $db = new db_query('SELECT * FROM common_feed WHERE 1 ' .   $where  .   $order  .   $limit_str);
        return $db->resultArray();
    }
}
?>